package com.hejia.bulbul.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hejia.alauda.entity.PopularizePlan;
import com.hejia.alauda.service.PopularizeService;
import com.hejia.alauda.utils.HttpResponse;

/**
 * 推广方案控制器
 * @author hyr
 *
 */
@Controller
@RequestMapping("popularizeplans")
public class PopularizePlanController extends BaseController {

	@Resource
	private PopularizeService popularizePlanService;
	
	@RequestMapping(value = "", method = RequestMethod.POST)
	@ResponseBody
	public HttpResponse add(PopularizePlan plan, ModelMap model){
		HttpResponse response = new HttpResponse();
		try {
			PopularizePlan addedPaln = popularizePlanService.add(plan);
			response.setCode("201");
			response.setStatus("success");
			response.setMessage("新增推广方案成功");
			response.setData(addedPaln);

		} catch (Exception e) {

			response.setCode("400");
			response.setStatus("error");
			response.setMessage("新增推广方案失败 " + e.getMessage());
			response.setData("");
		}
		return response;
	}
	
	@RequestMapping(value = "delete", method = RequestMethod.POST)
	@ResponseBody
	public HttpResponse delete(long id, ModelMap model){
		HttpResponse response = new HttpResponse();
		try {
			popularizePlanService.deletePopularizePlan(id);
			response.setCode("201");
			response.setStatus("success");
			response.setMessage("删除推广方案成功");
			response.setData("");

		} catch (Exception e) {

			response.setCode("400");
			response.setStatus("error");
			response.setMessage("删除推广方案失败 " + e.getMessage());
			response.setData("");
		}
		return response;
	}
}
